package signalprocessing;



import ikelib.PlotColor;
import ikelib.drawTools;
import ikelib.wintime;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.LinkedList;

/**
 * 
 */

/**
 * @author Toshiharu Ikeda <ikeda.104@gmail.com>
 *
 */
public class PlotAccelaration extends PlotPaneYT {
	public PlotAccelaration() {
		super();
	}

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final int VMargin    = 3;
	private static final int HMargin   = 20;
	
	
	
	@Override
	public void paintComponent(Graphics g){
		// super.paintComponent(g);   
		Dimension dm = this.getSize();
		Graphics2D g2 = (Graphics2D)g;
		if(Col!=null){
			g2.setBackground(Col.ColorBackGround);
			g2.setColor(Col.ColorDataBW);
		}
		g2.clearRect(0,0,dm.width,dm.height);

		
		Rectangle rc = new Rectangle(new Point(),dm);// graphエリア
		if(YAxis != null){
			YAxis.drawScale(g2,PlotAxis.AxisPlacedRight,rc);//振幅軸の軸を書く
			TAxis.drawScale(g2,PlotAxis.AxisPlacedBottom,rc);//振幅軸の軸を書く
		}
		drawZero(true);
		setViewRect(rc);
		
		// データを描画
		PolyLine(g2);	
		
//		// 凡例を描画
		int legendPos = getLegendPosition();
//		int x = 0;
//		int y = 0;
//		int pos  = 0; 
//		
//		switch(legendPos){
//		case LegendPosTOP_LEFT:
//			x = HMargin;
//			y = VMargin;
//			pos = drawTools.POSITION_LEFT_TOP|drawTools.FILL_RECT;
//			break;
//		case LegendPosTOP_RIGHT:
//			x = dm.width - HMargin;
//			y = VMargin;
//			pos = drawTools.POSITION_RIGHT_TOP|drawTools.FILL_RECT;
//			break;
//		case LegendPosBOTTOM_RIGHT:
//			x = dm.width - HMargin;
//			y = dm.height - VMargin;
//			pos = drawTools.POSITION_RIGHT_BOTTOM|drawTools.FILL_RECT;
//			break;
//		case LegendPosBOTTOM_LEFT:
//			x = HMargin;
//			y = dm.height - VMargin;
//			pos = drawTools.POSITION_LEFT_BOTTOM|drawTools.FILL_RECT;
//			default:
//		}
//		
		if(legendPos != LegendPosNone){
			Integer[] idary = getChannel();
			int maxch = idary.length;
			LinkedList<String> m = new LinkedList<String>();
			for(int i=0;i<maxch;i++){
				int ch = idary[i];
				String mes = String.format("%04x ", ch);
				String name = getDataName(idary[i]);
				if(name != null) mes += name;
				m.add(mes);
			}
			// 文字列のリストを渡して描画
//			drawTools.drawText(g2, m, x,y,pos,true);
			Legend(g2,m,HMargin,VMargin,0);
		}

	}
	/**
	 * 自分と軸をrepaintする。
	 */
	public void repaintAll(){
		Rectangle r = new Rectangle(0,0,getWidth(),getHeight());
		repaint(r);
		//getParent().repaint();
		if(YAxis!=null){
			YAxis.repaintAll();
		}
		if(TAxis!=null){
			TAxis.repaintAll();
		}
	}
	/* (non-Javadoc)
	 * @see winchkgpkg.BasicView#onDataChange()
	 */
	@Override
	void onDataChange() {
		if(PolyLineCalc()){
			repaintAll();
		}
	}
	/* (non-Javadoc)
	 * @see PlotPane#PointCalc()
	 */
	@Override
	boolean PointCalc() {
		return false;
	}
	/* (non-Javadoc)
	 * @see PlotPane#repaintAllComponent()
	 */
	@Override
	void repaintAllComponent() {
		
	}
}
